#ifndef DODO_DEVDSP_H
#define DODO_DEVDSP_H

#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <linux/soundcard.h>

int InitDevDsp(int rate)
{	
	int fd;	/* sound device file descriptor */

	int size = 16;
	int channels = 1;

    int arg;	/* argument for ioctl calls */
    int status;   /* return status of system calls */

    /* open sound device */
    fd = open ( "/dev/dsp", O_RDWR );
    if ( fd < 0 )
    {
        perror ( "open of /dev/dsp failed" );
        exit ( 1 );
    }

    /* set sampling parameters */
    arg = size;	   /* sample size */
    status = ioctl ( fd, SOUND_PCM_WRITE_BITS, &arg );
    if ( status == -1 )
        perror ( "SOUND_PCM_WRITE_BITS ioctl failed" );
    if ( arg != size )
        perror ( "unable to set sample size" );

    arg = channels;  /* mono or stereo */
    status = ioctl ( fd, SOUND_PCM_WRITE_CHANNELS, &arg );
    if ( status == -1 )
        perror ( "SOUND_PCM_WRITE_CHANNELS ioctl failed" );
    if ( arg != channels )
        perror ( "unable to set number of channels" );

    arg = rate;	   /* sampling rate */
    status = ioctl ( fd, SOUND_PCM_WRITE_RATE, &arg );
    if ( status == -1 )
        perror ( "SOUND_PCM_WRITE_WRITE ioctl failed" );

	return fd;
}

void EndDevDsp(int fd )
{
    close ( fd );
}
	
#endif

